﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Web;
using Castle.ActiveRecord;
using System.Web.UI;
using System.IO;
using SimplePMT.Data;
using SimplePMT.Components;
using NHibernate.Expression;


namespace SimplePMT.Control
{
    public partial class ReleaseMangementControl : System.Web.UI.UserControl
    {
        public int major = 1;
        public int minor = 0;
        public int build = 1;
        public string[] taskContainerList;

        public bool AdminAccess = false;
        protected void Page_Load(object sender, EventArgs e)
        {
           
        }
        

        public override string ToString()
        {
            taskContainerList = BuildContainerList();
            Release[] currentReleaseArray = Release.FindAll(Order.Desc("ID"));
            if (currentReleaseArray.Length > 0)
            {
                major = currentReleaseArray[0].Major;
                minor = currentReleaseArray[0].Minor;
                build = currentReleaseArray[0].Build;
                build = build + 1;
            }
            string result = "";
            StringWriter writer = new StringWriter();
            HtmlTextWriter htmlWriter = new HtmlTextWriter(writer);
            this.Render(htmlWriter);
            result = writer.ToString();
            return result;
        }

        public string[] BuildContainerList()
        {
            TaskContainer[] containerItems = TaskContainer.FindAll(Expression.Eq("IsAWISHProject", true));
            string[] containerList = new string[containerItems.Length + 1];
            using (new SessionScope())
            {
                int i = 1;
                containerList[0] = "0=SELECT PROJECT";
                foreach (TaskContainer container in containerItems)
                {
                    containerList[i] = container.ID + "=" + container.Label;
                    i++;
                }
            }
            return containerList;
        }


    }
}